{template 'common/header-gw'}
<ul class="nav nav-tabs">
	<li{if $do == 'finance_info' || $do == 'account_list' || $do == 'display' || $do == 'register_flow' || $do == 'flow_control'} class="active"{/if}>
		<a href="{php echo url('system/content_provider/account_list');}">流量主</a>
	</li>
	<li{if $do == 'content_provider'} class="active"{/if}><a href="{php echo url('system/content_provider/content_provider');}">广告主</a></li>
</ul>
<style>
	.nav .nav-tabs-flow {
		border-bottom: 1px solid #ddd;
	}
	.nav-tabs-flow>li {
	    float: left;
	    margin-bottom: -1px;
	    	    font-size: 12px!important;
	}
	.nav-tabs-flow>li.active>a, .nav-tabs-flow>li.active>a:hover, .nav-tabs-flow>li.active>a:focus {
	    color: #555;
	    background-color: #fff;
	    border: 1px solid #ddd;
	    border-bottom-color: transparent;
	    cursor: default;
	    	    font-size: 12px!important;
	}
</style>
<div class="clearfix">
	{if $do != 'content_provider'}
	<div class="alert alert-info">
		<div>
			<i class="fa fa-info-circle"></i>
			免费用户默认开通流量主服务，如果要进行关闭，请升级为授权版或商业版。
		</div>
		<div>
			<i class="fa fa-info-circle"></i>
			免费用户对公众号进行标签设置后，可以对广告进行分成。
		</div>
	</div>
	{/if}
	{if $do != 'content_provider'}
	<ul class="nav nav-tabs-flow">
		<li{if $do == 'account_list' || $do == 'display' || $do == 'register_flow' || $do == 'flow_control'} class="active"{/if}>
			{if $flow_master_info['status'] == 4 || IMS_FAMILY == 'v'}
			<a href="{php echo url('system/content_provider/account_list');}">流量管理</a>
			{elseif $flow_master_info['status'] != 4}
			<a href="{php echo url('system/content_provider/display');}">流量管理</a>
			{/if}
		</li>
		{if !empty($commission_show) || $flow_master_info['status'] == 4}
		<li{if $do == 'finance_info'} class="active"{/if}><a href="{php echo url('system/content_provider/finance_info');}">财务信息</a></li>
		{/if}
	</ul>
	{/if}
	{if $do == 'display'}
	<div class="panel panel-default">
		<div class="panel-heading">申请流量主</div>
		<div class="panel-body">
			<div class="col-xs-7">
				<span>流量主: {if empty($flow_master_info['status'])}未申请{else}{$flow_master_info['status_text']}{/if}</span>
				{if $flow_master_info['status'] == 3 && !empty($flow_master_info['refuse_reason'])}
				<span class="help-block">
					<strong class="text-danger">{$flow_master_info['refuse_reason']}</strong>
				</span>
				{/if}
				<span class="help-block">只需简单申请，即可成为流量主，按月获取广告收入。广告资源优质丰富，数据统计精准透明。</span>
			</div>
			{if is_error($flow_master_info) || (!is_error($flow_master_info) && ($flow_master_info['status'] == 1 || $flow_master_info['status'] == 3))}
			<div class="col-xs-5">
				<span class="pull-right">
					<a class="btn btn-primary" href="{php echo url('system/content_provider/register_flow')}">申请流量主</a>
				</span>
			</div>
			{/if}
		</div>
	</div>
	{/if}
	{if $do == 'register_flow'}
	<div class="panel panel-default">
		<div class="panel-heading">申请流量主</div>
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form" enctype="multipart/form-data" id="form1">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">联系人</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="linkman" id="linkman" class="form-control" autocomplete="off" value="{$flow_master_info['linkman']}" placeholder="请输入联系人" />
						<div class="help-block">
							请填写联系人
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">电话</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="mobile" class="form-control" value="{$flow_master_info['mobile']}" autocomplete="off" placeholder="请输入电话" />
						<div class="help-block">
							请填写电话
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">联系地址</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="address" class="form-control" value="{$flow_master_info['address']}" autocomplete="off" placeholder="请输入联系地址" />
						<div class="help-block">
							请输入联系地址
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">身份证上传</label>
					<div class="col-sm-9 col-xs-12">
						<input type="file" name="id_card_photo">
						<div class="help-block">
							请上传身份证
						</div>
					</div>
				</div>
				{if !empty($flow_master_info['id_card_photo'])}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9 col-xs-12">
						<div class="input-group">
							<img src="{$flow_master_info['id_card_photo']}?time={php echo time()}" class="img-responsive img-thumbnail" width="150" />
						</div>
					</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">营业执照上传</label>
					<div class="col-sm-9 col-xs-12">
						<input type="file" name="business_licence_photo">
						<div class="help-block">
							请上传营业执照
						</div>
					</div>
				</div>
				{if !empty($flow_master_info['business_licence_photo'])}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9 col-xs-12">
						<div class="input-group">
							<img src="{$flow_master_info['business_licence_photo']}?time={php echo time()}" class="img-responsive img-thumbnail" width="150" />
						</div>
					</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9 col-xs-12">
						<input name="submit" type="submit" value="提交" class="btn btn-primary span2 js-register-flow" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</form>
		</div>
	</div>
	<script>
		require(['filestyle'], function(){
			$(".form-group").find(':file').filestyle({buttonText: '上传图片'});
		});
		$('.js-register-flow').click(function() {
			linkman = $('input[name="linkman"]').val();
			mobile = $('input[name="mobile"]').val();
			address = $('input[name="address"]').val();
			if (!linkman) {
				util.message('请填写联系人');
				return false;
			}
			if (!mobile) {
				util.message('请填写电话');
				return false;
			}
			if (!address) {
				util.message('请填写联系地址');
				return false;
			}
			return true;
		});
	</script>
	{/if}
	{if $do == 'account_list'}
		<div class="panel panel-info">
			<div class="panel-heading">筛选</div>
			<div class="panel-body">
				<form action="./index.php" method="get" role="form" class="form-horizontal">
					<input type="hidden" name="c" value="system">
					<input type="hidden" name="a" value="content_provider">
				
					<div class="form-group" style="margin-top:20px;margin-left: 40px">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">搜索</label>
						<div class="col-sm-8 col-lg-10 col-xs-12">
							<div class="input-group">
								<input type="hidden" name="type" value="{$_GPC['type']}">
								<input type="hidden" name="expiretime" value="{$_GPC['expiretime']}">
								<input type="text" class="form-control {if empty($_GPC['keyword']) && !empty($_GPC['s_uniacid'])}hide{/if}" placeholder="请输入微信公众号名称" name="keyword" id="s_keyword" value="{$_GPC['keyword']}">
								<input type="text" class="form-control {if empty($_GPC['s_uniacid'])}hide{/if}" placeholder="请输入微信公众号ID" name="s_uniacid" id="s_uniacid" value="{$_GPC['s_uniacid']}">
								<div class="input-group-btn">
									<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
									<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
									<ul class="dropdown-menu dropdown-menu-right" role="menu">
										<li><a href="javascript:;" onclick="$('#s_uniacid').addClass('hide').val('');$('#s_keyword').removeClass('hide');">根据公众号名称搜索</a></li>
										<li><a href="javascript:;" onclick="$('#s_uniacid').removeClass('hide');$('#s_keyword').addClass('hide').val('');">根据公众号ID搜索</a></li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="panel panel-default">
			<div class="panel-heading">
				详细数据
			</div>
			<div class="table-responsive panel-body">
				<table class="table table-hover">
					<thead>
						<tr>
							<th class="row-hover">公众号<i></i></th>
							<th style="width:300px;">标签<i></i></th>
							{if !empty($commission_show)}
							<th style="width:100px;">累计金额<i></i></th>
							{/if}
							<th style="width:100px;">状态<i></i></th>
							<th style="width:100px;">管理</th>
						</tr>
					</thead>
					<tbody>
						{loop $list $uni}
							{loop $uni['details'] $account}
						<tr>
							<td class="row-hover">
								<div class="col-xs-12 col-sm-12 col-md-2 col-lg-1">
									<img src="{php echo tomedia('headimg_'.$account['acid'].'.jpg');}?time={php echo time()}" class="" width="50" height="50"  onerror="this.src='resource/images/gw-wx.gif'" />
								</div>
								<div class="col-xs-12 col-sm-12 col-md-4 col-lg-5 item" style="font-size:16px;">
									{$account['name']}
									<br>
									<span class="help-block" style="font-size:13px;">类型:{if $account['level'] == '1'}普通订阅号{elseif $account['level'] == '2'}普通服务号{elseif $account['level'] == '3'}认证订阅号{elseif $account['level'] == '4'}认证服务号/认证媒体/政府订阅号{/if}</span>
								</div>
							</td>
							<td>
							{if $uni['flow_setting_enable'] == 2 && !empty($uni['flow_setting'])}
								{$uni['flow_setting']['ad_tags_str']}
							{else}
								未设置
							{/if}
							</td>
							{if !empty($commission_show)}
							<td>
							{if !empty($uni['flow_setting']['amount'])}
								{$uni['flow_setting']['amount']}
							{else}
								0
							{/if}
								元
							</td>
							{/if}
							<td>
							{if IMS_FAMILY == 'v' || $uni['flow_setting_enable'] == 2}
								已开通
							{elseif $uni['flow_setting_enable'] == 1}
								未开通
							{/if}
							</td>
							<td>
								<a href="{php echo url('system/content_provider/flow_control', array('uniacid' => $account['uniacid']))}">
									{if IMS_FAMILY == 'v' ||$uni['flow_setting_enable'] == 2}
									设置
									{elseif $uni['flow_setting_enable'] == 1}
									开通广告联盟
									{/if}
								</a>
							</td>
						</tr>
							{/loop}
						{/loop}
					</tbody>
				</table>
			</div>
		</div>
		<div class="pull-right">{$pager}</div>
	{/if}
	{if $do == 'flow_control'}
		<div class="panel panel-default">
			<div class="panel-heading">公众号信息</div>
			<div class="panel-body">
				<table class="table table-hover">
					<thead>
						<tr>
							<th class="row-hover">公众号<i></i></th>
							<th style="width:300px;">标签<i></i></th>
							{if !empty($commission_show)}
							<th style="width:150px;">累计金额<i></i></th>
							{/if}
							<th style="width:200px;">管理</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>
								<div class="col-xs-12 col-sm-12 col-md-2 col-lg-1">
									<img src="{php echo tomedia('headimg_'.$current_account['acid'].'.jpg');}?time={php echo time()}" class="" width="50" height="50"  onerror="this.src='resource/images/gw-wx.gif'" />
								</div>
								<div class="col-xs-12 col-sm-12 col-md-4 col-lg-5 item" style="font-size:16px;">
									{$current_account['name']}
									<br>
									<span class="help-block" style="font-size:13px;">类型:{if $current_account['level'] == '1'}普通订阅号{elseif $current_account['level'] == '2'}普通服务号{elseif $current_account['level'] == '3'}认证订阅号{elseif $current_account['level'] == '4'}认证服务号/认证媒体/政府订阅号{/if}</span>
								</div>
							</td>
							<td>{if $current_uniaccount['enable'] == 2 && !empty($current_uniaccount['current_tags_str'])}{$current_uniaccount['current_tags_str']}{elseif empty($current_uniaccount)}未设置{/if}</td>
							{if !empty($commission_show)}
							<td>{if !empty($current_uniaccount)}{$current_uniaccount['amount']}{else}0{/if}元</td>
							{/if}
							<td>
							{if IMS_FAMILY != 'v'}
								{if empty($current_uniaccount['enable']) || $current_uniaccount['enable'] == 1}
								<a href="#ad-tags" data-toggle="modal" class="btn btn-primary">开通</a>
								{elseif $current_uniaccount['enable'] == 2}
								<a href="javascript:;" class="btn btn-danger js-stop-provider" data-uniacid="{$_GPC['uniacid']}">停止</a>
								<a href="#ad-tags" data-toggle="modal" class="btn btn-primary">设置</a>
								{/if}
							{else}
								<a href="#ad-tags" data-toggle="modal" class="btn btn-primary">设置</a>
							{/if}
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		{if IMS_FAMILY != 'v' && $current_uniaccount['enable'] == 2}
		<div class="panel panel-default">
			<div class="panel-heading">
				应用信息
				<span class="pull-right" style="display:none;">
					<a href="">批量设置</a>
				</span>
			</div>
			<div class="panel-body">
				<div class="row">
					{if !empty($modulelist_available)}
					{loop $modulelist_available $list}
						<div class="col-xs-3" style="padding:20px;">
							<div class="col-xs-2">
								<img src="{$list['icon']}" width="48" height="48" class="img-rounded">
							</div>
							<div class="col-xs-6">
								{$list['title']}
								<br>
								<span class="help-block">广告类型:
									{if $list['flow_setting']['enable'] == 2 && !empty($list['flow_setting']['ad_types'])}
									{loop $list['flow_setting']['ad_types'] $ad_types}
										{$ad_types}
									{/loop}
									{else}
										未开通
									{/if}
								</span>
							</div>
							<div class="col-xs-4">
								<a href="#ad-types" data-toggle="modal" class="js-type-setting" data-module_name="{$list['name']}" data-uniacid="{$_GPC['uniacid']}" data-ad_types='{$list['ad_types']}'>
									{if $list['flow_setting']['enable'] == 2 && !empty($list['flow_setting']['ad_types'])}
										设置
									{else}
										开通
									{/if}
								</a>
							</div>
						</div>
					{/loop}
					{else}
						<div class="col-xs-3" style="padding:20px;">暂无可用应用</div>
					{/if}
				</div>
			</div>
		</div>
		{/if}
		<div class="modal fade" id="ad-tags">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-body" style="text-align:left;">
						<table class="table tb" style="min-width:568px;">
							<thead>
							<tr>
								<th style="width: 50px;" class="text-center">选择</th>
								<th>标签</th>
							</tr>
							</thead>
							<tbody>
							{if !empty($tag_list)}
								{loop $tag_list $tags}
									<tr>
										<td colspan="2">
											<label class="label label-info">{$tags['title']}</label>
										</td>
									</tr>
									{loop $tags['items'] $key $items}
									<tr>
										<td class="text-center"><input type="checkbox" id="chk_tag_{$key}" name="tagids[]" data-name="{$items}" value="{$key}" {if !empty($current_tags[$key])} checked{/if}></td>
										<td><label for="chk_tag_{$key}" style="font-weight:normal;" class="name">{$items}</label></td>
									</tr>
									{/loop}
								{/loop}
							{/if}
							</tbody>
						</table>
					</div>
					<div class="modal-footer">
						<div class="pull-left js-select-tag-error"></div>
						<input type="hidden" name="tag-select">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary js-select-tags" data-uniacid="{$_GPC['uniacid']}">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="ad-types">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-body" style="text-align:left;">
						<table class="table tb" style="min-width:568px;">
							<thead>
							<tr>
								<th style="width: 50px;" class="text-center">选择</th>
								<th>类型</th>
							</tr>
							</thead>
							<tbody class="js-types-show">
							
							</tbody>
						</table>
					</div>
					<div class="modal-footer">
						<input type="hidden" name="type-select">
						<input type="hidden" name="module_name">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary js-select-types" data-dismiss="modal" data-uniacid="{$_GPC['uniacid']}" data-module_name>确定</button>
					</div>
				</div>
			</div>
		</div>
		<script>
			$(function() {
				$('#ad-types').on('hidden.bs.modal', function () {
					$('#ad-types input[type="checkbox"]').prop('checked', false);
				});
				cloud_module_support_str = '{$cloud_module_support_str}';
				cloud_module_support_str = $.parseJSON(cloud_module_support_str);
			})
			$(document).on('click', '.js-type-setting', function() {
				var module_name = $(this).data('module_name');
				var uniacid = $(this).data('uniacid');
				var ad_types = $(this).data('ad_types');
				html = '';
				for (var i in cloud_module_support_str[module_name].ad_types) {
					html += '<tr>';
					html += '<td class="text-center">';
					html += '<input type="checkbox" id="chk_type_'+ i +'" name="typeids[]" data-name="' + cloud_module_support_str[module_name].ad_types[i] + '" value="'+ i +'"></td>';
					html += '<td><label for="chk_type_'+ i +'" style="font-weight:normal;" class="name">' +
					cloud_module_support_str[module_name].ad_types[i] + '</label></td></tr>';

				}
				$('.js-types-show').html(html);
				$('.js-select-types').data('module_name', module_name);
				$.post("{php echo url('system/content_provider/ad_type_get')}", {'module_name' : module_name, 'uniacid' : uniacid}, function(data) {
					data = $.parseJSON(data);
					if (data.message.errno == 0) {
						for (var i in data.message.message) {
							$('#chk_type_' + i).prop('checked', true);
						}
					} else {
						util.message(data.message.message, '', 'error');
					}
				});
			});
			$(document).on('click', 'input[name="tagids[]"]', function() {
				checks = $('input[name="tagids[]"]:checked');
				if (checks.length > 0) {
					$('.js-select-tag-error').html('');
				}
			})
			$('.js-select-tags').click(function(){
				var chks = $('input[name="tagids[]"]:checked');
				var tagids = [];
				var uniacid = $(this).data('uniacid');
				if (chks) {
					$.each(chks, function(){
						tagids.push($(this).val());
					});
					$('input[name=tag-select]').val(tagids.join('@'));
				} else {
					$('input[name=tag-select]').val('');
				}
				if (tagids.length == 0) {
					$('.js-select-tag-error').html('请至少选择一个标签');
					return;
				} else {
					$('.js-select-tag-error').html('');
					$(this).attr('data-dismiss', 'modal');
					$.post("{php echo url('system/content_provider/flow_control')}", {'type' : 'tags', 'tagids' : tagids, 'enable' : 2, 'uniacid' : uniacid}, function(data) {
						data = $.parseJSON(data);
						if (data.message.errno == 0) {
							util.message(data.message.message, data.redirect, 'success');
						} else {
							util.message(data.message.message, data.redirect, 'error');
						}
					});
				}
			});
			$('.js-select-types').click(function(){
				var chks = $('input[name="typeids[]"]:checked');
				var typeids = [];
				var module_name = $(this).data('module_name');
				var uniacid = $(this).data('uniacid');
				if (chks) {
					$.each(chks, function(){
						typeids.push($(this).val());
					});
					$('input[name=type-select]').val(typeids.join('@'));
				} else {
					$('input[name=type-select]').val('');
				}
				$.post("{php echo url('system/content_provider/flow_control')}", {'type' : 'types', 'typeids' : typeids, 'enable' : 2, 'module_name' : module_name, 'uniacid' : uniacid}, function(data) {
					data = $.parseJSON(data);
					if (data.message.errno == 0) {
						util.message(data.message.message, data.redirect, 'success');
					} else {
						util.message(data.message.message, data.redirect, 'error');
					}
				});
			});
			$(document).on('click', '.js-stop-provider', function() {
				var uniacid = $(this).data('uniacid');
				$.post("{php echo url('system/content_provider/flow_control')}", {'type' : 'tags', 'enable' : 1, 'uniacid' : uniacid}, function(data) {
					data = $.parseJSON(data);
					if (data.message.errno == 0) {
						util.message(data.message.message, data.redirect, 'success');
					} else {
						util.message(data.message.message, data.redirect, 'error');
					}
				});
			});
		</script>
	{/if}
	{if $do == 'finance_info'}
	<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin: 10px -1em 1em 0px;">
		<div class="navbar-header">
			<a class="navbar-brand" href="{php echo url('system/content_provider/finance_info')}">数据统计</a>
			<ul class="nav navbar-nav navbar-right">
				<li {if $_GPC['type'] == 1}class="active"{/if}><a href="{php echo url('system/content_provider/finance_info', array('type' => '1'))}">今日</a></li>
				<li {if $_GPC['type'] == 2}class="active"{/if}><a href="{php echo url('system/content_provider/finance_info', array('type' => '2'))}">昨日</a></li>
				<form class="navbar-form navbar-left" role="search" id="form1">
					<input name="c" value="system" type="hidden">
					<input name="a" value="content_provider" type="hidden">
					<input name="do" value="finance_info" type="hidden">
					{php echo tpl_form_field_daterange('datelimit', array('start' => date('Y-m-d', $params['starttime']),'end' => date('Y-m-d', $params['endtime'])))}
				</form>
			</ul>
		</div>
	</nav>
	<div class="panel panel-default">
		<div class="panel-heading">账户流水</div>
		<div class="panel-body">
			<table class="table table-hover">
				<thead>
					<tr>
						<th>时间</th>
						<th>广告曝光度</th>
						<th>广告点击量</th>
						<th>收入金额</th>
					</tr>
				</thead>
				<tbody>
					{loop $finance_items $item}
					<tr>
						<td>
							{$item['extra_date']}
						</td>
						<td>
							{$item['view']}
						</td>
						<td>
							{$item['click']}
						</td>
						<td>
							{$item['amount']}元
						</td>
					</tr>
					{/loop}
				</tbody>
			</table>
		</div>
	</div>
	<div class="pull-right">{$pager}</div>
	<script>
		require(['jquery', 'daterangepicker'], function(c, $) {
			$(function() {
				$('.daterange').on('apply.daterangepicker', function(ev, picker) {
					$('#form1')[0].submit();
				});
			});
		});
	</script>
	{/if}
	
	{if $do == 'content_provider'}
		<iframe src="{$iframe}" marginheight="0" marginwidth="0" frameborder="0" width="100%" style="height:2000px;" scrolling="no" allowTransparency="true"></iframe>
	{/if}
	
</div>
{template 'common/footer-gw'}